import java.lang.ref.SoftReference;
import java.util.Arrays;

public class Example {

    public static int add(int a,int b) {
        return a+b;
    }
    public static int add(int a,int b,int c) {
        return a+b+c;
    }

    //可变参数 代码阅读性不高
    public static int add(int... array) {
        int ret = 0;
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
        }
        return ret;
    }

    /*public static int add(int... array) {
        return 1;
    }*/

    public static void main4(String[] args) {
        int[] array = {1,2,3};
        System.out.println(add(array));
        System.out.println(add(1,2,3,4,5,6,7));
        System.out.println(add(1,2,3,4,5));
        System.out.println(add(1,2,3,9,8,7,6,5));
    }

    public static void func(int[] array) {
        array = new int[10];//修改了指向
    }
    public static void func2(int[] array) {
        array[0] = 10;//修改了指向的内容
    }
    public static int[] func3(int[] array) {
        //数组作为返回值
        return new int[10];
    }

    public static void main(String[] args) {
        int[] ret = func3(new int[]{1,2,3});
        System.out.println(Arrays.toString(ret));
    }


    //网易原题2016
    String str = new String("good");
    char[ ] ch = { 'a' , 'b' , 'c' };

    public static void main1(String args[]) {
        Example ex = new Example();
        ex.change(ex.str,ex.ch);
        System.out.print(ex.str + " and ");
        System.out.print(ex.ch);
    }
    public void change(String str,char[ ] ch){//引用类型
        str = "test ok";
        ch[0] = 'g';
    }

    public static boolean isAdmin(String userId){
        return userId.toLowerCase()=="admin";
    }
    public static void main2(String[] args){
        String s1 = "abc"+"def";//1 "abcdef"
        String s2 = new String(s1);//2
        if(s1.equals(s2))//3比较内容
        {
            System.out.println(".equals succeeded");//4
        }
        if(s1==s2)//5比较地址
            System.out.println("==succeeded");//6

        String s11 = "abc";
        String s22 = s11 + "def";
    }
    public static int countSegments(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }
        int count = 0;
        String[] strings = s.split(" ");
        for (String x : strings) {
            if (x.length() != 0) {
                count++;
            }
        }
        return count;
    }

    public static String toLowerCase(String s) {
        String ret = s.toLowerCase();
        return ret;
    }

    public static String toLowerCase1(String s) {
        StringBuilder ret = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            //大写字母进行转换
            if (ch <= 'A' && ch <= 'Z') {
                ret.append((char) (ch+32));
            }else {
                //小写字母直接拼接
                ret.append(ch);
            }
        }
        return ret.toString();
    }

    public static void main3(String[] args) {
        int ret = countSegments("Hello, my name is John");
        System.out.println(ret);
        String ret1 = toLowerCase("abcABC");
        System.out.println(ret1);
    }
}
